package com.example.tests;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

import static com.example.tests.GroupDataGenerator.loadGroupsFromXmlFile;
import static com.example.tests.GroupDataGenerator.loadGroupsFromCsvFile;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;


public class GroupCreationTests extends TestBase {
	
	
	@DataProvider
	public  Iterator<Object[]>  groupsFromFile() throws IOException{
		return wrapGroupsForDataProvider(loadGroupsFromXmlFile(new File("groups.xml"))).iterator();
	}
		

	@Test (dataProvider = "groupsFromFile")
	public void testGroupCreationWithValidData(GroupData group) {
		// Старый список групп
		SortedListOf<GroupData> oldList 
			= new SortedListOf<GroupData>(app.getGroupHelper().getGroups());
		
		// Создание
		app.getGroupHelper().createGroup(group);
		
		// Новый список групп
		SortedListOf<GroupData> newList = app.getGroupHelper().getUiGroups();
		// Сравнение
		assertThat(newList, equalTo(oldList.withAdded(group)));
	}

}
